$(function(){
	$(".coll_body").eq(2).show();
	$(".coll_body").eq(2).children('a').eq(0).addClass("active");
	$(".Collapsing").eq(2).children('a').children('span').addClass("rotate");
	$(".Collapsing").eq(2).click(function(){
		$(".Collapsing").eq(2).toggleClass("active");
		$(this).children('.coll_body').children('a').eq(0).toggleClass("active");
	})
})

//	租户列表
	var pageSize = 15;
	var currentPage = 1; 
	ajaxTest(currentPage);
	
	function ajaxTest(currentPage) {
		$.ajax({
				type:"post",
				url:serverIP+"/user/customer/list",
				dataType:"json",
				xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
	            data: {page:currentPage,pageSize:pageSize},
				success:function (data) {
					if(data.code==0){
						let result=data.data.list.result;
						var strVar = "";
						result.map(function(u){
							if(u.status==01){
								status="启用"
							}else{
								status="停用"
							}
							strVar += "              <tr>";
						    strVar += "                <td>"+u.customerId+"<\/td>\n";
						    strVar += "                <td>"+u.name+"<\/td>\n";
						    strVar += "                <td>"+u.userName+"<\/td>\n";
						    strVar += "                <td>"+u.remark+"<\/td>\n";
						    strVar += "                <td>"+u.phone+"<\/td>\n";
						    strVar += "                <td>"+status+"<\/td>\n";
						    strVar += "                <td class=\"noExl\">\n"; 
						    strVar += "                		<div>\n"; 
						    strVar += "                			<span class=\"btn edit\" value="+u.customerId+">\n"; 
						    strVar += "                				<i class=\"icon-edit\"></i>编辑\n"; 
						    strVar += "                			</span>\n"; 
						    strVar += "                			<span class=\"btn delete\" value="+u.customerId+">\n"; 
						    strVar += "                				<i class=\"icon-trash\"></i>删除\n"; 
						    strVar += "                			</span>\n";
						    strVar += "                		</div>\n";
						    strVar += "                <\/td>\n"; 
						    strVar += "              <\/tr>";
						})
						$('.print-tbody').html(strVar);
					//分页
						$("#page").paging({
							pageNo: data.data.list.curPage,
							totalPage: data.data.list.totalPage,
							totalSize: data.data.list.totalRow,
							callback: function(currentPage) {
								ajaxTest(currentPage); 
							}
						});
					}else{
						alert(data.msg);
						window.location.href="login.html";
					}/*if-End*/
				}
		})
	}
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
}
$('.add').click(function(){
	window.location.href="addcustomer.html";
})
$("body").on("click",".edit",function(){
	var cid=$(this).attr("value");
	window.location.href="editcustomer.html?cid="+cid;
})
$("body").on("click",".delete",function(){
	if(confirm("确定要删除本条信息么")){
		var cid=$(this).attr("value");
		$.ajax({  
	        type : "POST",  
	        url : serverIP+'/user/customer/del',  
	        data : {
	        	customerId:cid
	        },
	        xhrFields: {
	            withCredentials: true    // 设置sessionId相同
	        },
	        success : function(){  
	        	window.location.reload();
	        }  
	    });
	}
}); 
